home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 003 / db3tips3.arc / DB3DATES.TXT next >
Encoding:
Text File  |  1986-12-21  |  4.5 KB  |  121 lines

  1.                      Working Day Calculator
  2.        (PC Magazine Vol 5 No 16 Sept 30, 1986 Power User)
  3.  
  4.      WORKDAYS.PRG uses dBASE's DOW() function to calculate elapsed
  5. business days (excluding weekends and company holidays) between any
  6. two dates.  This is useful, for example, in determining how long it
  7. takes to process insurance claims, how long it takes for sales to
  8. show up in bank deposits, etc.  It can also help in projecting lead
  9. times for scheduling production or in writing proposals.  If you
  10. declare the opening variables PUBLIC rather than PRIVATE, the results
  11. will be available to the calling program.
  12.      Editor's Note:  A few lines have been added to you can also use
  13. it to forecast a future promise date, and also so you can pass the
  14. parameters as date variables as well as character strings.  The
  15. resulting program handles a variety of inputs.
  16.      To use WORKDAYS.PRG for calculating business days elapsed, you
  17. pass two parameters -- the start and end dates -- to the program:
  18.  
  19. DO workdays with "04/06/86","05/06/86"
  20.  
  21.      Note that the final /86 may be omitted from either or both
  22. character strings.  You can also pass date variables: dBASE's TYPE()
  23. function is used to determine what kind of input you've passed, and,
  24. if it's a string, it is converted to date format.  The five lines of
  25. code that begin IF LEN(p1)=5 can be replaced with this one-line IIF()
  26. statement if you're using dBASE III Plus:
  27.  
  28. p1=CTOD(IIF(LEN(p1)=5,p1+"/"+STR(YEAR(DATE())-1900,2),p1))
  29.  
  30. If you'd like to use WORKDAYS to calculate promist dates, the first
  31. parameter is the start date as show above, and the second is the number
  32. of business days until delivery.  For example:
  33.  
  34. DO workdays with "05/28",35
  35.  
  36. The program will return 07/17/86, 35 weekdays (excluding Memorial Day
  37. and the 4th of July).
  38.  
  39. *** WORKDAYS.PRG: Calculates business days elapsed, past or future
  40.  
  41. * p1 may be 5 or 8 character or a dBASE date; p2 may also be a number
  42. PRIV holidays,days,start,end
  43. PARA p1,p2
  44. SET TALK OFF
  45. * Enter your company's holidays; these must be edited each year
  46. STOR 0 TO start,days
  47. holidays='01/01, 02/17, 05/26, 07/04, 09/01, 10/13, 11/27, 11/28, 12/25, 12/26'
  48. IF TYPE('p1')='C'
  49.   IF LEN(p1)=5
  50.     p1=CTOD(p1+"/"+STR(YEAR(DATE())-1900,2))
  51.   ELSE
  52.     p1=CTOD(p1)
  53.   ENDIF
  54. ENDIF p1 is the date if it entered as a string
  55.  
  56. IF TYPE('2')$'CD'
  57.   * if p2 is a string or date
  58.   IF TYPE('p2')='C'
  59.     IF LEN(p2)=5
  60.       p2=CTOD(p2+"/"+STR(YEAR(DATE())-1900,2))
  61.     ELSE
  62.       p2=CTOD(p2)
  63.     ENDIF
  64.   ENDIF p2 is now a date
  65.   start=p1
  66.   DO WHILE start<p2
  67.     IF STR(DOW(start),1)$'23456' .AND..NOT. SUBS(DTOC(start),1,5)$holidays
  68.       days=days+1
  69.     ENDIF
  70.     start=start+1
  71.   ENDDO
  72.   ? "Work days between",01,"&",p2,"--"+STR(days,4),"days."
  73. ELSE
  74.   * if p2 was a number
  75.   end=p1
  76.   DO WHILE days<p2
  77.     IF STR(DOW(end),1)$'23456' .AND..NOT. SUBS(DTOC(end),1,5)$holidays
  78.       days=days+1
  79.     ENDIF
  80.     end=end+1
  81.   ENDDO
  82.   DO WHILE STR(DOW(end),1)$'17' .OR> SUBS(DTOC(end),1,5)$holidays
  83.     end=end+1
  84.   ENDDO
  85.   ? p1,"plus"+STR(p2,4)+" work days:",end
  86. ENDIF
  87.  
  88. -----------------------------------------------------------------
  89.                         Pay Up or Lock Up
  90.         (PC Magazine Vol 5 No 22 Dec 23, 1986 Power User)
  91.  
  92.      Here is a simple but effective way to ensure payment from a
  93. customer for the work you've done in programming a custom application.
  94. Just place a trap procedure like the one below in the front end of your
  95. program and set the cutoff date as desired.  If the system date is
  96. beyond your cutoff, the trap procedure deactivates the Esc key and
  97. starts an endless loop.  This will effectively render the program
  98. useless.
  99.      Note that the trap is defeated if the system date has not been
  100. set.  For maximum protection, your program should be compiled to
  101. disallow the possibility of someone removing these code lines.
  102.      After payment, just give a non-trapped version to your customer.
  103.  
  104. IF DATE() > CTOD('10/31/86')
  105.   SET ESCAPE OFF
  106.   CLEAR
  107.   SET COLOR TO R*
  108.   ? "30 DAYS ARE UP,"
  109.   ? "YOU HAVE NOT PAID FOR THIS PROGRAM."
  110.   ? "CALL ME FOR INFO."
  111.   DO WHILE .T.
  112.   ENDDO
  113. ENDIF
  114.  
  115.      Editor's Note:  You might soften the message by substituting
  116. something about a "30-day demonstration period."  And rather than send
  117. the client's computer into a complete coma, a WAIT statement followed
  118. by QUIT might be just as effective in getting payment without
  119. infuriating the valuable person looking at your screen.
  120.  
  121.